﻿
namespace PS.DataTypes
{
    /// <summary>
    /// Helper class for the PS.DataTypes namespace.
    /// </summary>
    public static class DataTypeHelper
    {
        /// <summary>
        /// Returns the elements with the smallest cost so far.
        /// TODO: Improve performance.
        /// </summary>
        /// <param name="list">
        /// Extension to the List class.
        /// </param>
        /// <returns>
        /// NodeRecord element.
        /// </returns>
        public static NodeRecord SmallestElement(this NodeRecord[] list)
        {
            int elementsCount = list.Length;
            NodeRecord nodeRecord = null;

            // Assign the first node that makes sense to compare
            foreach (NodeRecord record in list)
            {
                if (record != null) nodeRecord = record;
            }

            if (nodeRecord != null)
            {
                for (int i = 1; i < elementsCount; i++)
                {
                    NodeRecord currentNode = list[1];
                    if (currentNode == null) continue;
                    if (currentNode.CostSoFar < nodeRecord.CostSoFar) nodeRecord = currentNode;
                }
            }

            return nodeRecord;
        }
    }
}
